<!-- 特殊通道 -->
<template>
	<zh-app style="font-family: '阿里巴巴普惠体'">
		<!-- 导航栏 -->
		<zh-navbar title="特殊通道" color="#85a5ff" linear="right" :hideHome="true" />
		<zh-filterMenu >
			<!-- 年度 -->
			<zh-filterMenu-item isButton  :title="data.year+'年'" un-icon="" icon="tmicon-menu">
				
			</zh-filterMenu-item>
			<!-- 统筹区 -->
			<zh-filterMenu-item :title="data.areaName">
				<view hover-class="opactiy-7" v-for="(item,index) in data.areaCodeDict" :key="index"
					@tap="onSelectArea(item)"
					class="flex-1 flex-row flex flex-row-center-between" style="height: 76rpx;">
					<zh-text :color="item.dictKey===data.areaCode?'primary':''" :label="item.dictValue" />
					<tm-icon :font-size="24" color="primary" v-if="item.dictKey===data.areaCode" name="tmicon-check" />
				</view>	
			</zh-filterMenu-item>
		</zh-filterMenu>
		<zh-spin :load="data.loading" tip="智能匹配中，请耐心等候">
			<view v-if="!data.showFlag" >
				<zh-result  status="lock" color="amber" :showBtn="false" :title="data.operation.title" :subTitle="data.operation.subTitle"></zh-result>
				<view class="flex-row-center-center">
				<zh-button  label="返回" @click="goBack()"  linear="right"></zh-button>
				</view>
			</view>
			<!-- 提示语 -->
			<view  v-if="data.showFlag">
				<zh-result
					v-if="data.stuArr.length<=0"
					btnText="返回"
					title="系统提示"
					subTitle="未匹配到特殊通道信息，请联系学校开通"
					@click="goBack()"
				></zh-result>
				<zh-sheet v-if="data.stuArr.length>0" :round="5" :margin="[30, 30,30,0]" :padding="[20,20]" color="primary" text >
					<zh-text  class="text-weight-b" :label="data.fullName"></zh-text>
					<zh-text  style="text-indent: 2em;padding-top:10rpx" label="根据您的条件以及相关学校的招生要求，您具备以下学校的报名资格。"></zh-text>
					<zh-text  style="text-indent: 2em;padding-top:10rpx" color="red" label="若信息有误，请致电相关学校。"></zh-text>
				</zh-sheet>
				<!-- 可报名信息 -->
				<view  v-for="(stuItem, index) in data.stuArr" >
					
				<zh-card
					:margin="[30,30]"
					color="#4ec752" 
					text
					v-for="(item, index) in stuItem.enrollBeforeList"
					:key="item.enrollBeforeId"
				>
					<template v-slot:title>
						<view style="width: 100%;" >
						<zh-sheet 
						class="round-tl-6 round-tr-6 flex-center" 
						style="backgroundImage: linear-gradient(to right, #adc6ff, #2f54eb)"
						:padding="[20,20]"
						:margin="[0,0]"
						:height="45">
						<zh-text :fontSize="38" color="#ffffff" :label="stuItem.fullName"></zh-text>
					</zh-sheet>
						<view  style="width: 100%;" class="flex-row-center-between">
							<view style="border-left: 10rpx solid #4ec752 ">
							<zh-text  :fontSize="30" class="text-weight-b pl-10" :label="item.schoolName"></zh-text>
							</view>
							<zh-tag :followTheme="false" color="#4ec752" size="n" label="特殊通道"></zh-tag>
						</view >
						</view>
					</template>
					<template v-slot:content>
						<zh-desc prefixLabel="特殊通道类别" :prefixWidth="300"  v-model="item.configName" ></zh-desc>
						<zh-button block label="我要报名" @click="onBmClick(stuItem.studentEnrollPreId,item)" color="#4ec752" :followTheme="false"></zh-button>
					</template>
				</zh-card>
				</view>
			</view>
		</zh-spin>
		<zh-message ref="messageRef" :duration="2000"></zh-message>
		<zlb-footer></zlb-footer>
		<!-- 底部学生选择栏 -->
		<zh-modal title="系统提示" :content="data.error.message" cancelText="取消" :okText="data.error.code===1?'确认':'前往'" :overlayClick="false" v-model:show="data.showError" @ok="onOk" @cancel="onCancel"></zh-modal>
		
	</zh-app>
</template>
<script lang="ts" setup>
	import {ref, reactive} from "vue";
	import { onLoad ,onShow } from "@dcloudio/uni-app";
	// ------------------接收传入参数(组件)-------------------

	// ------------------钩子函数----------------------------
	// 初始化
	onLoad((options:any) => {
		if(options.areaCode){
		  data.areaCode=options.areaCode
		}
		getAreaCode()
		getYear()
	})
	onShow(() => {
	    getStus()
	});

	// ------------------变量区------------------------------
	let messageRef=ref();
	// 主数据
	const data = reactive({
		loading:false,
		showFlag:false,//是否显示报名信息
		showStudent:false,
		year:new Date().getFullYear(),
		areaCode:'',
		areaName:'报名区县',
		operation:{title:'不能办理该业务',subTitle:'本年度招生工作尚未开始'},
		areaCodeDict:[] as any,
		studentEnrollPreId:'',//将要报名的学生
		fullName:'',//学生姓名
		schoolCategory:'',//选择学生的学段
		// 可报名学生数组
		stuArr: [] as any,
		showError:false,
		error:{} as any,
		enrollBeforeList:[] as any//可报名信息
	})

	// ------------------方法区------------------------------
	//获取可选行政区划
	const getAreaCode=()=>{
	  $api.common.send.post("dict0028", {}).then((res: any) => {
			data.areaCodeDict = res.result||[];
			if(data.areaCodeDict.length>=1){
			  data.areaCode=data.areaCodeDict[0].dictKey
			  data.areaName=data.areaCodeDict[0].dictValue
			  checkBm()
			}
		}).catch(()=>{})
	}
	//选择行政区划
	const onSelectArea=async (item:any)=>{
		data.areaCode=item.dictKey
		data.areaName=item.dictValue
		checkBm()
	}
	//获取年度
	const getYear=()=>{
		$api.common.send.post("OperationCache0005", {}).then((res: any) => {
			data.year=res.result.year||new Date().getFullYear()
		}).catch(()=>{})
	}
	// 报名前信息检查
	const checkBm = async () => {
		data.loading=true
		//判断是否学生
		let studentRet=await $api.common.send.post("eduStudentEnroll0007",{})
		if(studentRet.result){
			data.operation.title='学生账号不能报名！'
			data.operation.subTitle='请登录家长浙里办账号进行报名！'
			data.showFlag=false
			data.loading=false
			return
		}
			//判断是否在业务期范围内
			const params={classify:'2',areaCode:data.areaCode}
			$api.common.send.post("OperationCache0001", params).then((res: any) => {
				let result=res.result
				if(result&&result.operation){
					let eduOperation :any=result.operation
					let YW002 :any={}//正式报名 第一轮
					let YW022 :any={}//补报 第二轮
					let YW010 :any={}//抢报 第三轮
					if(eduOperation){
						YW002=eduOperation.YW002
						YW022=eduOperation.YW022
						YW010=eduOperation.YW010
						if(YW002.flag||YW022.flag||YW010.flag){
							//报名中获取报名列表
							getStus()
						}else{
							data.loading=false
							if(YW002.type==='1'){
								data.operation.title='未在办理报名业务时间段内！'
								data.operation.subTitle=YW002.messagePrompts
								data.showFlag=false
								return
							}else if(YW002.type==='3'){
								data.operation.title='未在办理报名业务时间段内！'
								data.operation.subTitle=data.year+'年度义务教育段招生报名工作尚未开始！'
								data.showFlag=false
								return
							}else{
								if(YW022.type==='1'){
									data.operation.title='未在办理报名业务时间段内！'
									data.operation.subTitle=YW022.messagePrompts
									data.showFlag=false
									return
								}else if(YW002.type==='3'){
									data.operation.title='未在办理报名业务时间段内！'
									data.operation.subTitle=YW002.messageTip
									data.showFlag=false
									return
								}else{
									if(YW022.type==='1'){
										data.operation.title='未在办理报名业务时间段内！'
										data.operation.subTitle=YW010.messagePrompts
										data.showFlag=false
										return
									}else if(YW002.type==='3'){
										data.operation.title='未在办理报名业务时间段内！'
										data.operation.subTitle=YW022.messageTip
										data.showFlag=false
										return
									}else{
										data.operation.title='未在办理报名业务时间段内！'
										data.operation.subTitle=YW010.messageTip
										data.showFlag=false
										return
									}
								}
							}
						}
					}else{
						data.operation.title='未在办理报名业务时间段内！'
						data.operation.subTitle=data.year+'年度义务教育段招生报名工作尚未开始！'
						data.showFlag=false
						data.loading=false
						return
					}
					
				}else{
					data.operation.title='未在办理报名业务时间段内！'
					data.operation.subTitle=data.year+'年度义务教育段招生报名工作尚未开始！'
					data.showFlag=false
					data.loading=false
					return
				}
			}).catch(()=>{})
		
	}
	const getStus = () => {
		//获取可补报的学生信息
		const params={specialFlag:'1'}
		$api.common.send.post("eduStudentEnroll0059", params).then((res: any) => {
			data.stuArr=res.result||[]
			data.loading=false
			if(data.stuArr.length>0){
				data.showStudent=true
				data.showFlag=true
				getStudentInfo()
			}else{
				data.operation.title='没有需要报名的学生！'
				data.operation.subTitle='请前往当年适龄子女查看！'
				data.showFlag=false
			}
		}).catch((err:any)=>{
			data.loading=false
			openError(err)
		})
		
		
	}
	const openError=(error:any)=> {
		if(error.code>0){
			if(error.code===3){
				data.operation.title='没有开通特殊通道！'
				data.operation.subTitle='请联系学校开通！'
				data.showFlag=false
			}else{
				data.error=error
				data.showError=true
			}
		}	
	}
	const onOk=()=>{
		data.showError=false
		if(data.error.code===2){
			//前往我的报名
			$router.replace('/pages/edu/enroll/myEnroll',{})
		}
	}
	const onCancel=()=>{
		//关闭页面
		data.showError=false
	}

	const getStudentInfo=()=>{
		//获取学生信息详情
		let studentList=[] as any
		data.stuArr.forEach((item :any)=> {
			let enrollBeforeList=item.enrollBeforeList||[]
			if(enrollBeforeList.length>0){
				enrollBeforeList=enrollBeforeList.filter((beforeItem :any) => {
					return beforeItem.specialFlag === '1'
				})
				if(enrollBeforeList.length>0){
					item.enrollBeforeList=enrollBeforeList;
					studentList.push(item)
				}
				
			}
		});
		data.stuArr=studentList
		data.loading=false
	}
	const onBmClick=(studentEnrollPreId :string,item:any)=>{
		$router.replace('/pages/edu/enroll/enrollForm',{studentEnrollPreId:studentEnrollPreId,schoolId:item.schoolId,enrollBeforeId:item.enrollBeforeId+''})
	}
	const goBack=()=>{
		$router.back(1)
	}
</script>
<style lang="scss" scoped>
	.tips-card {
		width: 630rpx;
		margin: 24rpx 32rpx;
		padding: 34rpx 26rpx 26rpx;
		background-image: linear-gradient(to right, #F8FAFF, #EBF1FF);
		box-shadow: rgb(0 85 255 / 20%) 0px 2px 6px;
		
		.desc {
			color: #5E5E5E;
			font-size: 36rpx;
			font-weight: 500;
			text-indent: 64rpx;
			line-height: 160%;
		}
	}
</style>